package com.ssy.lingxi.pay.controller.feign;

import com.ssy.lingxi.common.controller.BaseController;
import com.ssy.lingxi.common.response.Wrapper;
import com.ssy.lingxi.pay.api.model.vo.request.*;
import com.ssy.lingxi.pay.api.model.vo.response.CreditFeignDetailVO;
import com.ssy.lingxi.pay.api.model.vo.response.CreditPayResponseVO;
import com.ssy.lingxi.pay.service.ICreditBillService;
import com.ssy.lingxi.pay.service.ICreditService;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * @menu 支付能力-授信
 * @author 伍将
 * @date 2020/8/13 20:22
 * @version 2.0.0
 */
@RestController
public class CreditFeignController extends BaseController {

    @Resource
    private ICreditService creditService;

    @Resource
    private ICreditBillService billService;

    /**
     * 初始化会员授信
     * @author 伍将
     * @date 2020/8/20
     **/
    @RequestMapping("/pay/credit/feign/init")
    public Wrapper<Void> init(@RequestBody @Valid CreditInitVO initVO) {
        return creditService.init(initVO);
    }

    /**
     * 查询会员授信
     * @param feignVO 上下级会员Id
     * @return 查询结果，如无授信，返回Null
     */
    @RequestMapping(value = "/pay/credit/feign/find", method = RequestMethod.POST)
    public Wrapper<CreditFeignDetailVO> findCredit(@RequestBody @Valid CreditFeignVO feignVO) {
        return creditService.findCredit(feignVO);
    }

    /**
     * 支付能力-新增会员授信 审批通过会员调用
     * @author 伍将
     * @date 2020/8/13 20:25
     **/
    @RequestMapping("/pay/credit/feign/add")
    public Wrapper<Void> add(@RequestBody @Valid CreditAddVO creditAddVO) {
        return creditService.add(creditAddVO);
    }

    /**
     * 支付能力-授信支付
     * @author 伍将
     * @date 2020/8/28
     **/
    @RequestMapping("/pay/credit/feign/pay")
    public Wrapper<CreditPayResponseVO> pay(@RequestBody @Valid CreditPayVO payVO) {
        return creditService.pay(payVO);
    }

    /**
     * 支付能力-授信退款
     * @param refundVO 接口参数
     * @return 退款结果
     */
    @RequestMapping("/pay/credit/feign/refund")
    public Wrapper<String> refund(@RequestBody @Valid CreditRefundVO refundVO) {
        return creditService.refund(refundVO);
    }

    /**
     * 冻结授信
     * @author 伍将
     * @date 2020/12/1
     **/
    @RequestMapping("/pay/credit/feign/updateCreditStatus")
    public Wrapper<Void> frozenCredit(@RequestBody @Valid FrozenCreditVO frozenCreditVO) {
        return creditService.frozenCredit(frozenCreditVO);
    }

    /**
     * 逾期通知
     * @author 伍将
     * @date 2021/1/22
     **/
    @RequestMapping("/pay/credit/feign/overdueNotice")
    public Wrapper<Void> overdueNotice(@RequestBody @Valid OverdueNoticeVO noticeVO) {
        return billService.overdueNotice(noticeVO.getTime() + " 23:59:59");
    }

    /**
     * 还款通知
     * @author 伍将
     * @date 2021/1/22
     **/
    @RequestMapping("/pay/credit/feign/repayNotice")
    public Wrapper<Void> repayNotice(@RequestBody @Valid RepayNoticeVO noticeVO) {
        return billService.repayNotice(noticeVO.getTime() + " 23:59:59");
    }

    /**
     * 账单通知
     * @author 伍将
     * @date 2021/1/22
     **/
    @RequestMapping("/pay/credit/feign/billNotice")
    public Wrapper<Void> billNotice(@RequestBody @Valid BillNoticeVO noticeVO) {
        return billService.billNotice(noticeVO.getTime());
    }
}
